package com.housekeeping.housekeeping.advertisingmanagement.service.impl;/*
 * @author  pyh
 * @date  2021/1/22 0022 上午 9:36
 * @version 1.0
 * @since JDK1.8_241
 */

import com.housekeeping.housekeeping.advertisingmanagement.dao.impl.SearchDaoImpl;
import com.housekeeping.housekeeping.advertisingmanagement.entity.AdMessages;
import com.housekeeping.housekeeping.advertisingmanagement.service.SearchService;
import com.housekeeping.housekeeping.advertisingmanagement.utils.Page;

import java.sql.SQLException;
import java.util.Collections;
import java.util.List;

public class SearchServiceImpl implements SearchService {
    private SearchDaoImpl searchDao = new SearchDaoImpl();

    @Override
    public Page<List<AdMessages>> getStatusList(int status, int page, int size) throws SQLException {
        Page<List<AdMessages>> objectPage = new Page<>();
        List<AdMessages> statusList = searchDao.getStatusList(status, (page - 1) * page, size);

        objectPage.setData(Collections.singletonList(statusList));
        //设置总条数（用于返回前端进行分页效果）
        objectPage.setSearchCount(true);
        //设置当前页为当前请求页
        objectPage.setSearchCount(true);
        return objectPage;
    }

    @Override
    public Page<List<AdMessages>> getSearchList(int status, String name,int page,int size) {
        Page<List<AdMessages>> objectPage = new Page<>();
        //int statusCount = searchDao.getCount(status);
        List<AdMessages> nameList = searchDao.getNameList(status, name, (page - 1) * size, size);
        int count = searchDao.getCount(status, name);

        objectPage.setData(Collections.singletonList(nameList));
        objectPage.setTotal(count);
        //设置当前页为当前请求页
        objectPage.setTotal(page);

        return objectPage;
    }
}
